{% extends "common/layout.html" %}
{% block content %}


    {#    <div class="row">#}
    <div class="row">
        <input class="form-control" id="uid" name="uid" style="display:none" value="{{ current_user.id }}">
        <div class="col-sm-10 col-sm-offset-1">
            <div class="row">
                <div class="col-sm-10 ">
                    <h2>{{ bookindex.projectname }}+{{ bookindex.gcname }}
{#                        <button type="button" class="btn btn-success" data-toggle="modal"#}
{#                                data-target="#exampleModal" style="margin-left: 10px"><span#}
{#                                class="glyphicon glyphicon-open"#}
{#                                aria-hidden="true"></span>上传项目资料#}
{#                        </button>#}
                    </h2>
                    <h4>
                        <span class="label label-success">{{ bookindex.sn }}</span>
                        <span class="label label-info">{{ bookindex.bname }}</span>
                    </h4>
                </div>

            </div>
        </div>
    </div>

    <div class="row">
        <!-- Nav tabs -->
        <div class="col-sm-10 col-sm-offset-1" style="margin-top: 30px">

            <ul class="nav nav-pills" role="tablist">
                <li role="presentation" class="active">
                    <a href="#one" aria-controls="one" role="tab" data-toggle="tab">招标策划
                        <span class="badge">{{ num[0] }}</span>
                    </a>
                </li>
                <li>
                    <button style="height: 40px" type="button" class="btn btn-success" data-toggle="modal"
                            data-classone="招标策划"
                            data-target="#exampleModal"><span
                            class="glyphicon glyphicon-open"
                            aria-hidden="true"></span>
                    </button>
                </li>
                <li role="presentation">

                    <a href="#two" aria-controls="two" role="tab" data-toggle="tab">发标阶段
                        <span class="badge">{{ num[1] }}</span>
                    </a>
                </li>
                    <li>
                    <button style="height: 40px" type="button" class="btn btn-success" data-toggle="modal"
                            data-classone="发标阶段"
                            data-target="#exampleModal"><span
                            class="glyphicon glyphicon-open"
                            aria-hidden="true"></span>
                    </button>
                </li>

                <li role="presentation">

                    <a href="#three" aria-controls="three" role="tab" data-toggle="tab">谈标阶段
                        <span class="badge">{{ num[2] }}</span>
                    </a>
                </li>
                    <li>
                    <button style="height: 40px" type="button" class="btn btn-success" data-toggle="modal"
                            data-classone="谈标阶段"
                            data-target="#exampleModal"><span
                            class="glyphicon glyphicon-open"
                            aria-hidden="true"></span>
                    </button>
                </li>

                <li role="presentation">

                    <a href="#four" aria-controls="four" role="tab" data-toggle="tab">定标阶段
                        <span class="badge">{{ num[3] }}</span>
                    </a>
                </li>
                    <li>
                    <button style="height: 40px" type="button" class="btn btn-success" data-toggle="modal"
                            data-classone="定标阶段"
                            data-target="#exampleModal"><span
                            class="glyphicon glyphicon-open"
                            aria-hidden="true"></span>
                    </button>
                </li>


            </ul>

            <!-- Tab panes -->
            <div class="tab-content">
                <div role="tabpanel" class="tab-pane active" id="one">
                    <div class="row" style="margin-top: 10px">
                        <row class="data-table">
                            <table class="table table-bordered table-hover">
                                <tr>

{#                                    <th class="info">文件种类</th>#}
                                    <th class="info">文件名称</th>
                                    <th class="info">文件大小</th>
                                    <th class="info">文件类型</th>
                                    <th class="info">上传时间</th>
                                    <th class="info">上传人员</th>
                                    <th class="info">下载文件</th>
                                </tr>
                                {% for item in alldetail[0] %}
                                    <tr>
{#                                        <th>{{ item.classtwo }}</th>#}
                                        <th>{{ item.name }}</th>
                                        <th>{{ item.size }}MB</th>
                                        <th>{{ item.type }}</th>
                                        <th>{{ item.created_time }}</th>
                                        <th>{{ item.creater.nickname }}</th>

                                        <th>
                                            {#                                            <a class="btn btn-warning"#}
                                            {#                                               href="{{ item.url }}">查看文件</a>#}
                                            <a href="{{ item.url }}" class="btn btn-warning" onclick="bookopenone()">
                                                查看文件
                                            </a>
                                            <button type="button" class="btn btn-danger" data-toggle="modal"
                                                    data-target="#conModal" data-id="{{ item.id }}">删除
                                            </button>
                                        </th>


                                    </tr>

                                    <script>
                                        function bookopenone() {
                                            var uid = {{ current_user.id }};
                                            var project = "{{ bookindex.projectname }}" + "{{ bookindex.gcname }}";
                                            var classone = "{{ item.classone }}";
                                            var classtwo = "{{ item.classtwo }}";
                                            var filename = "{{ item.name }}";
                                            console.log(filename);

                                            $.ajax({
                                                url: common_ops.buildUrl("/record/bookopenrecord"),
                                                type: "POST",
                                                data: {
                                                    part: "招定标档案信息存档",
                                                    project: project,
                                                    classone: classone,
                                                    classtwo: classtwo,
                                                    filename: filename,
                                                    uid: uid,
                                                    action: "查看",
                                                },
                                                dataType: 'json',
                                                success: function (res) {
                                                }
                                            });
                                        }
                                    </script>

                                {% endfor %}
                            </table>
                        </row>


                    </div>
                </div>

                <div role="tabpanel" class="tab-pane" id="two">
                    <div class="row" style="margin-top: 10px">
                        <row class="data-table">
                            <table class="table table-bordered table-hover">
                                <tr>

{#                                    <th class="info">文件种类</th>#}
                                    <th class="info">文件名称</th>
                                    <th class="info">文件大小</th>
                                    <th class="info">文件类型</th>
                                    <th class="info">上传时间</th>
                                    <th class="info">上传人员</th>
                                    <th class="info">下载文件</th>
                                </tr>
                                {% for item in alldetail[1] %}
                                    <tr>
{#                                        <th>{{ item.classtwo }}</th>#}
                                        <th>{{ item.name }}</th>
                                        <th>{{ item.size }}MB</th>
                                        <th>{{ item.type }}</th>
                                        <th>{{ item.created_time }}</th>
                                        <th>{{ item.creater.nickname }}</th>

                                        <th>
                                            <a href="{{ item.url }}" class="btn btn-warning" onclick="bookopentwo()">
                                                查看文件
                                            </a>
                                            <button type="button" class="btn btn-danger" data-toggle="modal"
                                                    data-target="#conModal" data-id="{{ item.id }}">删除
                                            </button>
                                        </th>
                                    </tr>

                                    <script>
                                        function bookopentwo() {
                                            var uid = {{ current_user.id }};
                                            var project = "{{ bookindex.projectname }}" + "{{ bookindex.gcname }}";
                                            var classone = "{{ item.classone }}";
                                            var classtwo = "{{ item.classtwo }}";
                                            var filename = "{{ item.name }}";

                                            $.ajax({
                                                url: common_ops.buildUrl("/record/bookopenrecord"),
                                                type: "POST",
                                                data: {
                                                    part: "招定标档案信息存档",
                                                    project: project,
                                                    classone: classone,
                                                    classtwo: classtwo,
                                                    filename: filename,
                                                    uid: uid,
                                                    action: "查看",
                                                },
                                                dataType: 'json',
                                                success: function (res) {
                                                }
                                            });
                                        }
                                    </script>

                                {% endfor %}
                            </table>
                        </row>


                    </div>
                </div>

                <div role="tabpanel" class="tab-pane" id="three">
                    <div class="row" style="margin-top: 10px">
                        <row class="data-table">
                            <table class="table table-bordered table-hover">
                                <tr>

{#                                    <th class="info">文件种类</th>#}
                                    <th class="info">文件名称</th>
                                    <th class="info">文件大小</th>
                                    <th class="info">文件类型</th>
                                    <th class="info">上传时间</th>
                                    <th class="info">上传人员</th>
                                    <th class="info">下载文件</th>
                                </tr>
                                {% for item in alldetail[2] %}
                                    <tr>
{#                                        <th>{{ item.classtwo }}</th>#}
                                        <th>{{ item.name }}</th>
                                        <th>{{ item.size }}MB</th>
                                        <th>{{ item.type }}</th>
                                        <th>{{ item.created_time }}</th>
                                        <th>{{ item.creater.nickname }}</th>

                                        <th>
                                            <a href="{{ item.url }}" class="btn btn-warning" onclick="bookopenthree()">
                                                查看文件
                                            </a>
                                            <button type="button" class="btn btn-danger" data-toggle="modal"
                                                    data-target="#conModal" data-id="{{ item.id }}">删除
                                            </button>
                                        </th>
                                    </tr>

                                    <script>
                                        function bookopenthree() {
                                            var uid = {{ current_user.id }};
                                            var project = "{{ bookindex.projectname }}" + "{{ bookindex.gcname }}";
                                            var classone = "{{ item.classone }}";
                                            var classtwo = "{{ item.classtwo }}";
                                            var filename = "{{ item.name }}";

                                            $.ajax({
                                                url: common_ops.buildUrl("/record/bookopenrecord"),
                                                type: "POST",
                                                data: {
                                                    part: "招定标档案信息存档",
                                                    project: project,
                                                    classone: classone,
                                                    classtwo: classtwo,
                                                    filename: filename,
                                                    uid: uid,
                                                    action: "查看",
                                                },
                                                dataType: 'json',
                                                success: function (res) {
                                                }
                                            });
                                        }
                                    </script>

                                {% endfor %}
                            </table>
                        </row>


                    </div>
                </div>

                <div role="tabpanel" class="tab-pane" id="four">
                    <div class="row" style="margin-top: 10px">
                        <row class="data-table">
                            <table class="table table-bordered table-hover">
                                <tr>
{#                                    <th class="info">文件种类</th>#}
                                    <th class="info">文件名称</th>
                                    <th class="info">文件大小</th>
                                    <th class="info">文件类型</th>
                                    <th class="info">上传时间</th>
                                    <th class="info">上传人员</th>
                                    <th class="info">下载文件</th>
                                </tr>
                                {% for item in alldetail[3] %}
                                    <tr>
{#                                        <th>{{ item.classtwo }}</th>#}
                                        <th>{{ item.name }}</th>
                                        <th>{{ item.size }}MB</th>
                                        <th>{{ item.type }}</th>
                                        <th>{{ item.created_time }}</th>
                                        <th>{{ item.creater.nickname }}</th>

                                        <th>
                                            <a href="{{ item.url }}" class="btn btn-warning" onclick="bookopenfour()">
                                                查看文件
                                            </a>
                                            <button type="button" class="btn btn-danger" data-toggle="modal"
                                                    data-target="#conModal" data-id="{{ item.id }}">删除
                                            </button>
                                        </th>
                                    </tr>
                                    <script>
                                        function bookopenfour() {
                                            var uid = {{ current_user.id }};
                                            var project = "{{ bookindex.projectname }}" + "{{ bookindex.gcname }}";
                                            var classone = "{{ item.classone }}";
                                            var classtwo = "{{ item.classtwo }}";
                                            var filename = "{{ item.name }}";

                                            $.ajax({
                                                url: common_ops.buildUrl("/record/bookopenrecord"),
                                                type: "POST",
                                                data: {
                                                    part: "招定标档案信息存档",
                                                    project: project,
                                                    classone: classone,
                                                    classtwo: classtwo,
                                                    filename: filename,
                                                    uid: uid,
                                                    action: "查看",
                                                },
                                                dataType: 'json',
                                                success: function (res) {
                                                }
                                            });
                                        }
                                    </script>

                                {% endfor %}
                            </table>
                        </row>


                    </div>
                </div>

                <div role="tabpanel" class="tab-pane" id="five">
                    <div class="row" style="margin-top: 10px">
                        <row class="data-table">
                            <table class="table table-bordered table-hover">
                                <tr>

{#                                    <th class="info">文件种类</th>#}
                                    <th class="info">文件名称</th>
                                    <th class="info">文件大小</th>
                                    <th class="info">文件类型</th>
                                    <th class="info">上传时间</th>
                                    <th class="info">上传人员</th>
                                    <th class="info">下载文件</th>
                                </tr>
                                {% for item in alldetail[4] %}
                                    <tr>
{#                                        <th>{{ item.classtwo }}</th>#}
                                        <th>{{ item.name }}</th>
                                        <th>{{ item.size }}MB</th>
                                        <th>{{ item.type }}</th>
                                        <th>{{ item.created_time }}</th>
                                        <th>{{ item.creater.nickname }}</th>

                                        <th>
                                            <a href="{{ item.url }}" class="btn btn-warning" onclick="bookopenfive()">
                                                查看文件
                                            </a>
                                            <a class="btn btn-danger"
                                               href="{{ buildUrl('/book/detaildelete') }}?id={{ item.id }}">删除</a>
                                        </th>
                                    </tr>
                                    <script>
                                        function bookopenfive() {
                                            var uid = {{ current_user.id }};
                                            var project = "{{ bookindex.projectname }}" + "{{ bookindex.gcname }}";
                                            var classone = "{{ item.classone }}";
                                            var classtwo = "{{ item.classtwo }}";
                                            var filename = "{{ item.name }}";

                                            $.ajax({
                                                url: common_ops.buildUrl("/record/bookopenrecord"),
                                                type: "POST",
                                                data: {
                                                    part: "招定标档案信息存档",
                                                    project: project,
                                                    classone: classone,
                                                    classtwo: classtwo,
                                                    filename: filename,
                                                    uid: uid,
                                                    action: "查看",
                                                },
                                                dataType: 'json',
                                                success: function (res) {
                                                }
                                            });
                                        }
                                    </script>

                                {% endfor %}
                            </table>

                        </row>


                    </div>
                </div>
            </div>


        </div>
    </div>


    <script>
        $('#myTabs a').click(function (e) {
            e.preventDefault()
            $(this).tab('show')
        })
    </script>

    {#    </div>#}


    {#    确认模态框#}
    <div class="modal fade" id="conModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">操作确认</h4>
                </div>
                <div class="modal-body">
                    <p>是否确定删除?</p>
                    <input type="text" style="display:none" id="deleteid" name="deleteid">
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button class="btn btn-danger do-delete" type="submit" name="delete" id="delete">确定删除</button>
                </div>
            </div>
        </div>
    </div>



    {#    模态框#}
    <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
        <div class="modal-dialog" role="document">
            {#    等待模态#}
            <div class="modal fade" id="loadingModal">
                <div style="width: 200px;height:20px; z-index: 20000; position: absolute; text-align: center; left: 50%; top: 50%;margin-left:-100px;margin-top:-10px">
                    <div class="progress progress-striped active" style="margin-bottom: 0;">
                        <div class="progress-bar" style="width: 100%;"></div>
                    </div>
                    <h5 style="color:black"><strong>正在上传文件，请耐心等待...</strong></h5>
                </div>
            </div>


            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="exampleModalLabel">上传存档文件</h4>
                </div>
                <div class="modal-body">


                    <script type="text/javascript">
                        $(function () {
                            function objInit(obj) {
                                return $(obj).html('<option>请选择</option>');
                            }

                            var arrData = {
                                招标策划:
                                    {
                                        "招标要求及界面划分": "",
                                        "招标策划": "",
                                        "特批单位(特批报告)": "",
                                        "单位邀请(单位邀请表+邀请函回执)": "",
                                    },

                                发标阶段:
                                    {
                                        "施工图纸": "",
                                        "招标文件及会签": "",
                                        "清单": "",
                                        "招标申请": "",
                                    },
                                谈标阶段:
                                    {
                                        "答疑/澄清": "",
                                        "约谈记录": "",
                                        "开标记录表": "",
                                        "清标文件": "",
                                        "技术标评审": "",
                                    },
                                定标阶段:
                                    {
                                        "定标报告": "",
                                        "定标清单": "",
                                        "定标审批": "",
                                        "中标通知书": "",
                                        "其他文件": "",
                                    },

                            };
                            $.each(arrData, function (pF) {
                                $('#selF').append('<option>' + pF + '</option>');
                            });
                            $('#selF').change(function () {
                                objInit('#selT');
                                objInit('#selC');
                                $.each(arrData, function (pF, pS) {
                                    if ($('#selF option:selected').text() == pF) {
                                        $.each(pS, function (pT, pC) {
                                            $('#selT').append('<option>' + pT + '</option>');
                                        });
                                        $('#selT').change(function () {
                                            objInit('#selC');
                                            $.each(pS, function (pT, pC) {
                                                if ($('#selT option:selected').text() == pT) {
                                                    $.each(pC.split(","), function () {
                                                        $('#selC').append('<option>' + this + '</option>');
                                                    })
                                                }
                                            })

                                        });
                                    }
                                })
                            });
                        });
                    </script>


                    {#暂存变量#}
                    <input class="form-control" id="pid" name="pid" style="display:none" value="{{ bookindex.id }}">
                    <input class="form-control" id="sn" name="sn" style="display:none" value="{{ bookindex.sn }}">
                    <input class="form-control" id="uid" name="uid" style="display:none" value="{{ current_user.id }}">

                    <div class="form-group">
                        <label class="control-label">招标阶段:</label>
                        <select class="form-control " name="classone" id="selF">
                            <option>请选择</option>

                        </select>
                    </div>

{#                    <div class="form-group">#}
{#                        <label class="control-label">文件类型:</label>#}
{#                        <select class="form-control " name="classtwo" id="selT" onchange="showtype()">#}
{#                        </select>#}
{#                    </div>#}

                    {#投标文件显示第几次投标#}
                    <script type="text/javascript">
                        function showtype() {
                            var selectValue = $("#selT").find("option:selected").text();
                            if (selectValue == '投标文件') {
                                $("#typeform").show();
                            } else {
                                $("#typeform").hide();
                            }
                        }
                    </script>


                    <div class="form-group" style="display:none" id="typeform">
                        <label class="control-label">投标批次</label>
                        <select class="form-control " name="pc" id="pc">
                            <option></option>
                            <option>第一次投标</option>
                            <option>第二次投标</option>
                            <option>第三次投标</option>
                            <option>第四次投标</option>
                            <option>第五次投标</option>
                            <option>第六次投标</option>
                            <option>第七次投标</option>
                            <option>第八次投标</option>
                            <option>第九次投标</option>

                        </select>
                    </div>


                    <div class="form-group">
                        <label class="control-label">上传文件:</label>
                        <div id="input">
                            <input id="upload_input" class="admin img-fluid" type="file" multiple="multiple">
                        </div>
                    </div>

                    <div class="modal-footer">
                        <button class="btn btn-success do-upload" enctype="multipart/form-data">确定上传
                        </button>
                    </div>


                </div>
            </div>
        </div>
    </div>


    {#删除数据#}
    <script>
        $(".do-delete").click(function () {
            var btnaction = $(this);
            if (btnaction.hasClass("disable")) {
                common_ops.alert("还没提交上去了，别瞎点")
                return
            }

            var deleteid = $("input[id=deleteid]").val();


            $.ajax({
                url: common_ops.buildUrl("/book/detaildelete"),
                type: "GET",
                data: {
                    id: deleteid,
                },
                dataType: 'json',
                success: function (res) {
                    btnaction.removeClass("disabled");
                    var callback = null;
                    if (res.code == 200) {
                        callback = function () {
                        };
                    }
                    common_ops.alert(res.msg, callback);
                    setTimeout(function () {
                        $('#conModal').modal('hide');
                        $(".modal-backdrop.fade").hide();
                        window.location.href = common_ops.buildUrl("/book/bookdetail?id=" + res.data.pid);
                        $("#exampleModal").trigger("click");
                    }, 1000)

                }
            });

        });
    </script>



    <script>
        {#编辑赋值#}
        $('#exampleModal').on('show.bs.modal', function (event) {
            var button = $(event.relatedTarget); // Button that triggered the modal
            var classone = button.data('classone');
            console.log(classone);
            document.getElementById("selF").value = classone;

        });


        {#删除赋值#}
        $('#conModal').on('show.bs.modal', function (event) {
            var button = $(event.relatedTarget);
            var deleteid = button.data('id');
            document.getElementById("deleteid").value = deleteid;
        });

    </script>



{% endblock %}

{% block js %}
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
    {#    <script src="static/js/moment-with-locales.js"></script>#}
    <script src="https://cdn.bootcss.com/bootstrap-datetimepicker/4.17.47/js/bootstrap-datetimepicker.min.js"></script>
    <script src="{{ buildStaticUrl('/js/book/bookdetail.js') }}"></script>

{% endblock %}
